#include <QCoreApplication>
#include <QtSql>
#include "tcpfile.h"
#include "tcpmessage.h"
#include <QTextCodec>
#include <QSysInfo>
#include "sql.h"

QString sysType;
QString pathPre;
TcpFile *tcpFile;
TcpMessage *tcpMessage;
QMap<int, QMap<QString, QString>> blogMap_c, blogMap_cpp, blogMap_php, blogMap_java, blogMap_android;
QMap<int, QMap<QString, QString>> blogMap_harmony, blogMap_stm32;
QMap<QString, QString> blogOff;
QMap<QString, QString> resOff;
QString userBlogOff, userResOff, blogComOff, userComOff;

int main(int argc, char *argv[])
{
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    QCoreApplication a(argc, argv);

    // 获取系统类型
    QString sysType = QSysInfo::productType();
    pathPre = QString("../data/");
    //QProcess::startDetached("../data/kill_tcp.sh");
    // 结束占用端口的进程
    system("lsof -i:5555 | grep server | grep -v grep |cut -c 9-13 | xargs kill -9");
    system("lsof -i:6666 | grep server | grep -v grep |cut -c 9-13 | xargs kill -9");
    // 打开数据库
    if(openDB())
    {
//        blogMap_c = selectBlog("type", "C");
//        blogMap_cpp = selectBlog("type", "C++");
//        blogMap_php = selectBlog("type", "PHP");
//        blogMap_java = selectBlog("type", "Java");
//        blogMap_android = selectBlog("type", "Android");
//        blogMap_harmony = selectBlog("type", "HarmonyOS");
//        blogMap_stm32 = selectBlog("type", "STM32");
        blogOff.insert("C", 0);
        blogOff.insert("C++", 0);
        blogOff.insert("PHP", 0);
        blogOff.insert("Java", 0);
        blogOff.insert("Android", 0);
        blogOff.insert("HarmonyOS", 0);
        blogOff.insert("STM32", 0);
    }
    else
    {
        qDebug() << "open db failed";
    }

    // 开启文件传输TCP服务器
    tcpFile = new TcpFile(5555);
    qDebug()<<tcpFile->getHostIP();
    tcpFile->startTCP();
    // 开启消息传输TCP服务器
    tcpMessage = new TcpMessage(6666);
    qDebug()<<tcpMessage->getHostIP();
    tcpMessage->startTCP();

    return a.exec();
}
